package examination.Qunar_09_21;


public class Solution1 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 比较两个版本号的大小
     * @param version1 string字符串 
     * @param version2 string字符串 
     * @return int整型
     */
    public int compareVersion (String version1, String version2) {
        String[] strings1 = version1.split("\\.");
        String[] strings2 = version2.split("\\.");
        int len1 = strings1.length;
        int len2 = strings2.length;
        int num1 = 0, num2 = 0;
        int num10 = 0, num20 = 0;
        boolean flag1 = true, flag2 = true;
        for (int i = 0; i < strings1.length; i++) {
            char ch = strings1[i].charAt(0);
            int x = 0;
            if (ch > '0' && ch <= '9') {
                x = Integer.parseInt(strings1[i]);
                num1 = num1 * 10 + x;
            }
            if (x != 0) {
                flag1 = false;
            }
            if (flag1) {
                num10++;
            }
        }
        for (int i = 0; i < strings2.length; i++) {
            char ch = strings2[i].charAt(0);
            int x = 0;
            if (ch > '0' && ch <= '9') {
                x = Integer.parseInt(strings2[i]);
                num2 = num2 * 10 + x;
            }
            if (x != 0) {
                flag2 = false;
            }
            if (flag2) {
                num20++;
            }
        }
        if (num10 < num20) {
            return 1;
        } else if(num10 > num20) {
            return -1;
        } else {
            if (num1 > num2) {
                return 1;
            } else if (num1 < num2) {
                return -1;
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        System.out.println(solution1.compareVersion("0.1.Alpha", "1.Final"));
    }
}